package com.crm.system.service.impl.customerManager;

import cn.hutool.core.lang.UUID;
import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.common.util.DateUtil;
import com.crm.common.util.EasyExcelUtil;
import com.crm.dao.mapper.customerManager.ChsCustomerTagMapper;
import com.crm.model.entity.customerManager.ChsCustomerTag;
import com.crm.model.entity.customerManager.ChsCustomerTagExample;
import com.crm.model.entity.customerManager.Customer;
import com.crm.model.entity.customerManager.CustomerPay;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.qo.customerManager.CustomerPayQO;
import com.crm.model.vo.customerManager.CustomerPayDetailVO;
import com.crm.model.vo.customerManager.CustomerPayExport;
import com.crm.model.vo.customerManager.CustomerPayVO;
import com.crm.service.customerManager.CustomerDbService;
import com.crm.service.customerManager.CustomerPayDbService;
import com.crm.service.customerManager.CustomerTagDbService;
import com.crm.system.service.customerManager.CustomerPayService;
import com.crm.system.service.customerManager.CustomerTagService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Author:chaifuyou
 * @Date: 2021/4/30 9:47
 */
@Service
public class CustomerTagServiceImpl implements CustomerTagService {
    
    @Autowired
    private CustomerTagDbService customerTagDbService;

    /**
     * 客户标签列表
     * @param pageIndex
     * @param pageSize
     * @param sortName
     * @param sortOrder
     * @return
     */
    @Override
    public DhPageInfo<ChsCustomerTag> selectCustomerTagList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<ChsCustomerTag> resultList = customerTagDbService.selectCustomerList();
        PageInfo<ChsCustomerTag> pageInfo = new PageInfo<ChsCustomerTag>(resultList);
        return new DhPageInfo<ChsCustomerTag>(pageInfo, resultList);
    }

    @Override
    public Boolean addTag(ChsCustomerTag chsCustomerTag) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        chsCustomerTag.setId(UUID.randomUUID().toString());
        chsCustomerTag.setCreateTm(new Date());
        chsCustomerTag.setCreatePersonId(userAccount.getAccountId());
        return customerTagDbService.addTag(chsCustomerTag);
    }

    @Override
    public Boolean deleteCustomerTagById(String id) {
        return customerTagDbService.deleteTag(id);
    }

    @Override
    public int selectTagNameSize(ChsCustomerTag chsCustomerTag) {
        return customerTagDbService.selectTagNameSize(chsCustomerTag.getTag());
    }

    @Override
    public int selectTagSize(ChsCustomerTag chsCustomerTag) {
        return customerTagDbService.selectTagSize(chsCustomerTag.getTag());
    }
}
